package com.kfm.hotel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.yulichang.extension.mapping.config.DeepConfig;
import com.kfm.hotel.domain.Room;
import com.kfm.hotel.domain.SysUser;
import com.kfm.hotel.service.RoomService;
import com.kfm.hotel.mapper.RoomMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author 10854
* @description 针对表【room】的数据库操作Service实现
* @createDate 2023-06-05 09:37:17
*/
@Service
public class RoomServiceImpl extends ServiceImpl<RoomMapper, Room>
    implements RoomService{

    @Override
    public PageInfo<Room> list(Room room, Integer page, Integer limit) {

        // 查询条件
        QueryWrapper<Room> wrapper = new QueryWrapper<>();
//        if (user.getUsername() != null && !user.getUsername().equals("")) {
//            wrapper.like("username", user.getUsername());
//        }
        wrapper.eq("state", 1);
        wrapper.eq("is_del", 0);

        // 查询并封装成 PageInfo 对象
        // 分页
        PageHelper.startPage(page, limit);
        List<Room> rooms = listDeep(wrapper, conf -> conf.loop(true));
        PageInfo<Room> pageInfo = new PageInfo<>(rooms);
        return pageInfo;
    }

    @Override
    public boolean updateState(Integer id, Integer state) {
        UpdateWrapper<Room> wrapper = new UpdateWrapper<>();
        wrapper.set("room_state", state);
        wrapper.eq("id", id);
        return update(wrapper);
    }

    @Override
    public Map<String, Integer> getRoomCount() {
        return getBaseMapper().getRoomCount();
    }
}




